package com.example.security1.web.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.example.security1.web.menu.entity.Menu;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

@Data
@TableName("rbac_user")
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable, UserDetails {

    @TableId(type = IdType.AUTO)
    private Long uId;

    private String username;
    private String password;
    private String avatar;
    private Integer sex;
    private String phone;
    private Integer userType;
    private Integer isAdmin;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    private Date updateTime;

    // 账户是否过期(1 未过期，0已过期)
    private boolean isAccountNonExpired = true;

    // 账户是否被锁定(1 未锁定，0已锁定)
    private boolean isAccountNonLocked = true;

    // 密码是否过期(1 未过期，0已过期)
    private boolean isCredentialsNonExpired = true;

    // 账户是否可用(1 可用，0 删除用户)
    private boolean isEnabled = true;

    //由于authorities不是数据库里面的字段，所以要排除他，不然mybatis-plus找不到该字段会报错
    @TableField(exist = false)
    Collection<? extends GrantedAuthority> authorities;

    // 用户权限列表，不属于用户表字段，需要排除
    @TableField(exist = false)
    List<Menu> permissionList;
}
